package com.appstore.action;

import java.io.File;
import java.util.Date;

import org.apache.struts2.ServletActionContext;

import com.appstore.util.FileCopy;
import com.appstore.util.FileNameUtil;
import com.opensymphony.xwork2.ActionSupport;

public class FileUploadAction extends ActionSupport {

	private File doc;
	private String docFileName;
	private String docContentType;
	private String filePath;
	private String docTempName;
	private boolean hasUpload;
	private boolean hasSuccess;
	
	public File getDoc() {
		return doc;
	}

	public void setDoc(File doc) {
		this.doc = doc;
	}

	public String getDocFileName() {
		return docFileName;
	}

	public void setDocFileName(String docFileName) {
		this.docFileName = docFileName;
	}

	public String getDocContentType() {
		return docContentType;
	}

	public void setDocContentType(String docContentType) {
		this.docContentType = docContentType;
	}

	public String getDocTempName() {
		return docTempName;
	}

	public void setDocTempName(String docTempName) {
		this.docTempName = docTempName;
	}

	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	public boolean isHasUpload() {
		return hasUpload;
	}

	public void setHasUpload(boolean hasUpload) {
		this.hasUpload = hasUpload;
	}

	public boolean isHasSuccess() {
		return hasSuccess;
	}

	public void setHasSuccess(boolean hasSuccess) {
		this.hasSuccess = hasSuccess;
	}

	
	
	
	@Override
	public String execute() throws Exception {
		this.setHasUpload(true);
		this.docTempName = FileNameUtil.getFileName(this.docFileName) +"-"+ new Date().getTime()
		        + FileNameUtil.getExtention(this.docFileName);
		File temp = new File(ServletActionContext.getServletContext()
		        .getRealPath(this.filePath) + "/" + this.docTempName );
		FileCopy.copy(doc, temp);
		this.setHasSuccess(true);
		return "success";
	}

}
